package com.leejie.config;



import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;

import javax.servlet.ServletContext;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.util.Arrays;

public class TestOne {
    public static void main(String[] args) throws IOException {

        String getenv = System.getenv("ALLUSERSPROFILE");
        System.out.println("properties:   "+getenv);


            /*List<String> list = new ArrayList<>();
            list.add("周杰伦");
            list.add("王力宏");
            list.add("陶喆");
            list.add("林俊杰");
            Stream<Integer> stream = list.stream().map(String::length);
            stream.forEach(System.out::println);*/

        String str = new String("李杰");
        System.out.println(str);
        byte[] bytesASCII = str.getBytes("ASCII");
        byte[] bytesGBK = str.getBytes("GBK");
        byte[] bytesutf8 = str.getBytes("utf-8");
        System.out.println("ASCII编码："+Arrays.toString(bytesASCII));
        System.out.println("GBK编码："+Arrays.toString(bytesGBK));
        System.out.println("UTF-8编码："+Arrays.toString(bytesutf8));
        System.out.println("===================================================");


        //获取utf-8对应的的字符集
        Charset charset = Charset.forName("utf-8");
        //将字符串通过utf-8进行编码转化成字节
        byte[] bytes = str.getBytes(charset);
        //再将字节根据相同的编码格式进行解码
        String string = new String(bytes, "utf-8");
        System.out.println(string);


        //使用编码器和解码器
        ByteBuffer encode = charset.encode(str);
        CharBuffer decode = charset.decode(encode);
        CharsetEncoder encoder = charset.newEncoder();
//        CharsetDecoder decoder = charset.newDecoder();
        encoder.encode(decode);


        File file = new File("C:\\Users\\Leejie\\Desktop\\微信公众号.txt");
        FileInputStream in = new FileInputStream(file);
        int length = 0;
        byte[] bytes1 = new byte[1024];
        while((length = in.read(bytes1)) != -1){
            System.out.print(new String(bytes1,0,length));
        }
        in.close();

    }

}
